package com.example.mpdata.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mpdata.dao.UserMapper;
import com.example.mpdata.po.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class TestApi {
    @Resource
    private UserMapper userMapper;

    /**
     * http://localhost:8080/user/page?current=1&size=3
     *
     * {
     *   "records": [
     *     {
     *       "id": 1,
     *       "name": "Jone",
     *       "age": 18,
     *       "email": "test1@baomidou.com"
     *     },
     *     {
     *       "id": 2,
     *       "name": "Jack",
     *       "age": 20,
     *       "email": "test2@baomidou.com"
     *     },
     *     {
     *       "id": 3,
     *       "name": "Tom",
     *       "age": 28,
     *       "email": "test3@baomidou.com"
     *     }
     *   ],
     *   "total": 5,
     *   "size": 3,
     *   "current": 1,
     *   "orders": [],
     *   "hitCount": false,
     *   "searchCount": true,
     *   "pages": 2
     * }
     *
     * @param page
     * @return
     */
    @GetMapping("/user/page")
    public IPage<User> getPage(Page<User> page){
        return userMapper.selectPageVo(page);
    }
}
